<template>
	<view class="p-2 oubSubmit">
		<view class="bg-white rounded-10 mb-3 p-3">
			<view class="mb-2">调拨合计</view>
			<view class="flex j-start a-center mb-3">
				<view class="label">调拨数量</view>
				<view class="inp">
					<u--input :disabled="true" type="text" v-model="formData.count" placeholder="请输入" clearable
						fontSize="12px"></u--input>
				</view>
			</view>
			<view class="flex j-start a-center">
				<view class="label">合计成本价</view>
				<view class="inp">
					<u--input :disabled="true" type="text" v-model="formData.costPrice" placeholder="请输入" clearable
						fontSize="12px"></u--input>
				</view>
				<text>元</text>
			</view>
		</view>
		<view class="bg-white rounded-10 mb-3 p-3">
			<view class="mb-2">接收方</view>
			<view class="flex j-start a-center mb-3">
				<view class="label">调入仓库</view>
				<view class="inp flex j-sb a-center rounded-10" style="border: 1px solid #dadbde;padding: 12rpx 10rpx;"
					@click="showPicker=true">
					<view class="font" style="color: #333;" v-if="formData.name">{{formData.name}}</view>
					<view class="font" style="color: #c0c4cc;" v-if="!formData.name">调入仓库</view>
					<u-icon name="arrow-down" color="#c0c4cc" size="14"></u-icon>
				</view>
			</view>
		</view>

		<view class="position-fixed left-0 bottom-0 bg-white p-4 w-100">
			<view class="btn m-o col-8 rounded-40 " style="height: 70rpx;" @click="submit">提交</view>
		</view>

		<u-picker :show="showPicker" :columns="userColumns" keyName="name" @confirm="confirmPicker"
			@cancel="cancelSearch"></u-picker>
	</view>
</template>

<script>
	import {
		allotSaleList,saveAllot
	} from '@/common/api/sales.js'
	import {
		warehouseByUser,
		itLibraryList,
		getWarehouseLists
	} from '@/common/api/itLibrary.js'
	import {
		customerList
	} from '@/common/api/customer.js'
	export default {
		name: "",
		mixins: [],
		data() {
			return {
				formData: {
					name: '',
					phone: '',
					address: '',
					customerId:'',
					salePrice:0,
					costPrice:0,
					count:0
					
				},
				showPicker: false,
				userColumns: []
			}
		},
		onLoad() {
			this.getSaleList();
			this.getCustomerList()
		},
		watch: {},
		computed: {},
		methods: {
			getSaleList() {
				this.formData.salePrice=0;
				this.formData.costPrice=0;
				allotSaleList().then(res => {
					this.listsData = res.data;
					this.formData.count=res.data.length;
					res.data.forEach(i=>{
						this.formData.salePrice+=Number(i.salePrice);
						this.formData.costPrice+=Number(i.costPrice);
					})
				})
			},
			getCustomerList() {
				this.userColumns = []
				getWarehouseLists({}).then(res => {
					this.userColumns.push(res.data)
				})
			},
			confirmPicker(val) {
				this.formData.name = val.value[0].name;
				this.formData.id = val.value[0].id;
				this.showPicker = false;
			},
			cancelSearch() {
				this.showPicker = false;
			},
			submit() {
				if(this.formData.name==''){
					uni.$u.toast('请选择调入仓库');
					return 
				}
				saveAllot({
					productList:this.listsData,
					cashEntrepotId:this.formData.id,
					saleUserId:this.app_user_info.id
				}).then(res=>{
					uni.$u.toast('提交成功');
					this.navigateBack();
				})
			}
		}
	}
</script>

<style lang="scss">
	.oubSubmit {
		.u-input {
			padding: 8rpx 10rpx !important;
		}

		.label {
			width: 190rpx;
			text-align: right;
			margin-right: 10rpx;
		}

		.inp {
			width: 400rpx;
			margin-right: 10rpx;
		}
	}
</style>